﻿using System.Text.RegularExpressions;
using Peter.Common;

namespace Peter.Sdw.Logic
{
   /// <summary>
   /// A simple regex used to remove text.
   /// </summary>
   public class RemoveRegex : ViewModelBase
   {
      private string m_Text = string.Empty;

      /// <summary>
      /// Gets or Sets the regex text.
      /// </summary>
      public string Text
      {
         get { return this.m_Text; }
         set
         {
            this.m_Text = value;
            this.RaisePropertyChanged ("Text");
         }
      }

      /// <summary>
      /// Removes this regex from the given text.
      /// </summary>
      /// <param name="text">Text to remove regex from.</param>
      /// <returns>The text with the regex removed.</returns>
      public string RemoveFrom (string text)
      {
         if (string.IsNullOrEmpty (text))
            return string.Empty;
         if (!string.IsNullOrEmpty (this.Text)) {
            return Regex.Replace (text, this.Text, string.Empty);
         }
         return text;
      }
   }
}
